/*   
=============================================================================== 
WResize is the jQuery plugin for fixing the IE window resize bug 
............................................................................... 
                                               Copyright 2007 / Andrea Ercolino 
------------------------------------------------------------------------------- 
LICENSE: http://www.opensource.org/licenses/mit-license.php 
WEBSITE: http://noteslog.com/ 
=============================================================================== 
*/ 
 
( function( $ )  
{ 
    $.fn.wresize = function( f )  
    { 
        version = '1.1'; 
        wresize = {fired: false, width: 0}; 
 
        function resizeOnce()  
        { 
            if ( $.browser.msie ) 
            { 
                if ( ! wresize.fired ) 
                { 
                    wresize.fired = true; 
                } 
                else  
                { 
                    var version = parseInt( $.browser.version, 10 ); 
                    wresize.fired = false; 
                    if ( version < 7 ) 
                    { 
                        return false; 
                    } 
                    else if ( version == 7 ) 
                    { 
                        //a vertical resize is fired once, an horizontal resize twice 
                        var width = $( window ).width(); 
                        if ( width != wresize.width ) 
                        { 
                            wresize.width = width; 
                            return false; 
                        } 
                    } 
                } 
            } 
 
            return true; 
        } 
 
        function handleWResize( e )  
        { 
            if ( resizeOnce() ) 
            { 
                return f.apply(this, [e]); 
            } 
        } 
 
        this.each( function()  
        { 
            if ( this == window ) 
            { 
                $( this ).resize( handleWResize ); 
            } 
            else 
            { 
                $( this ).resize( f ); 
            } 
        } ); 
 
        return this; 
    }; 
 
} ) ( jQuery );

var $j = jQuery.noConflict();

var IsDuplicateScrollEvent = 0;

function SetupGoogleAnalyticsTrackEvents()
{
		TrackEventsForMinimumPageScroll();
}

function TrackEventsForMinimumPageScroll()
{
	 $j(window).scroll(function(){
		 var scrollPercent = GetScrollPercent();
	 
		 if(scrollPercent > 80)
		 {
			 if(IsDuplicateScrollEvent == 0)
			 { 
				 IsDuplicateScrollEvent = 1;
                 //alert("Page Scrolled to 80% in " + document.location.href);
				 TrackEvent("Content Engagement", "Scrolled To 80%", document.location.href);
			 }
		 }
	 }); 
}

function GetScrollPercent()
{
		 var bottom = $j(window).height() + $j(window).scrollTop();
		 var height = $j(document).height();

		 return Math.round(100*bottom/height);
}
												
function TrackEvent(Category, Action, Label)
{
	 pageTracker._trackEvent(Category, Action, Label);
	 
}     

$j.fn.GAEvent = function () {
	var eventCategory = $j(this).attr("type");
	var eventAction = $j(this).attr("rel");
	var eventTitle = $j(this).attr("title");
	
	$j(this).attr("onclick", "_gaq.push(['_trackEvent', '"+eventCategory+"', '"+eventAction+"', '"+eventTitle+"']);");

}
$j.fn.affixBrand = function() {
	var brandingContent = $j(this).html();
	
	if ( $j(document).width() > 1235 ) {
		$j(this).css({
			"position" : "fixed",
			"bottom" : "0px",
			"right" : "0px",
			"z-index" : "0"
		});
	}
	else {
		$j(this).css({
			"position" : "static",
			"bottom" : "auto",
			"right" : "auto",
			"z-index" : "1"
		});
	}
}
$j.fn.YearsInBiz = function() {
	var d = new Date
	var CurrentYear = d.getFullYear();
	var StartYear = 1992;
	var BizYears = CurrentYear - StartYear;
	
	$j(this).text(BizYears);
}
$j(document).ready(function(){

	$j("table.altRows tr:odd").addClass("even");
	$j(".BizYears").YearsInBiz();
	$j("#inquiryForm").validate();
  $j("#builtByBC").affixBrand();
	$j(".GAEvent").each(function() {
    $j(this).GAEvent();
  });
	SetupGoogleAnalyticsTrackEvents();

});
$j(window).wresize(function() {
	$j("#builtByBC").affixBrand();
});
